package com.ds.lens.data.controller;

import com.ds.lens.data.service.LensDashboardService;
import com.ds.lens.data.vo.BaseOutVO;
import com.ds.lens.data.vo.factory.VOFactory;
import com.ds.lens.data.vo.in.PagedConditionInVO;
import com.ds.lens.data.vo.in.User;
import com.ds.lens.data.vo.in.v2.dashboard.LensDashboardInVO;
import com.ds.lens.data.vo.in.v2.dashboard.LensDashboardListInVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author WeiShaoying
 * @date 2019/11/6 下午2:32
 */
@RestController
@Api(value = "Lens Dashboard controller")
@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class LensDashboardController {

    @Autowired
    LensDashboardService lensDashboardService;

    @ApiOperation(value = "save dashboard")
    @PostMapping(value = "/lens/dashboard/save")
    public BaseOutVO saveDashboard(@RequestBody @Valid LensDashboardInVO inVO,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.saveDashboard(inVO, user));
    }

    @ApiOperation(value = "update dashboard")
    @PostMapping(value = "/lens/dashboard/update")
    public BaseOutVO updateDashboard(@RequestBody @Valid LensDashboardInVO inVO,
                                   @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.updateDashboard(inVO, user));
    }



    @ApiOperation(value = "delete dashboard")
    @GetMapping(value = "/lens/dashboard/delete")
    public BaseOutVO deleteDashboard(@RequestParam("ids") List<Long> ids,
                                   @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.deleteDashboard(ids, user));
    }



    @ApiOperation(value = "list dashboard")
    @PostMapping(value = "/lens/dashboard/list")
    public BaseOutVO queryDashboard(@RequestBody @Valid PagedConditionInVO<LensDashboardListInVO> inVO,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.queryDashboard(inVO, user));
    }

    @ApiOperation(value = "getDashboardDetail")
    @GetMapping(value = "/lens/dashboard/getDashboardDetail")
    public BaseOutVO getDashboardDetail(@RequestParam("id") Long id,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.getDashboardDetail(id,user));
    }

    @ApiOperation(value = "addFavorite")
    @GetMapping(value = "/lens/dashboard/addFavorite")
    public BaseOutVO addFavorite(@RequestParam("id") Long id,
                                       @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.addFavorite(id,user));
    }
    @ApiOperation(value = "removeFavorite")
    @GetMapping(value = "/lens/dashboard/removeFavorite")
    public BaseOutVO removeFavorite(@RequestParam("id") Long id,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.removeFavorite(id, user));
    }


    @ApiOperation(value = "share dashboard")
    @GetMapping(value = "/lens/dashboard/share")
    public BaseOutVO shareDashboard(@RequestParam("id") Long id,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.share(id,user));
    }

    @ApiOperation(value = "unshare dashboard")
    @GetMapping(value = "/lens/dashboard/unshare")
    public BaseOutVO unshareDashboard(@RequestParam("id") Long id,
                                    @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.unshare(id,user));
    }


    @ApiOperation(value = "get recommended dashboard")
    @PostMapping(value = "/lens/dashboard/recommended")
    public BaseOutVO getRecommendedDashboard(@RequestBody @Valid PagedConditionInVO<LensDashboardListInVO> inVO,
                                             @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensDashboardService.getRecommendedDashboard(inVO,user));
    }


}
